package com.taobao.taobaowidget.test;

import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.graphics.Color;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ListView;
import android.widget.TextView;

import com.taobao.taobaowidget.popupspinner.PopupSpinnerView;
import com.taobao.taobaowidget.popupspinner.PopupSpinnerView.OnPopupItemListener;
import com.taobao.taobaowidget.popupspinner.data.BaseDataInterface;
import com.taobao.taobaowidget.popupspinner.data.PopupSpinnerData;

public class PopupSpinnerActivity extends Activity {

	TextView mPopText;
	TextView mPopTextImage;
	ListView mListView;
	List<String> data;
	List<BaseDataInterface> sharedata;
	List<BaseDataInterface> sharedata2;
	PopupSpinnerView mPopSpinner;
	PopupSpinnerView mPopSpinner2;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.popupspinner_layout);
		mPopText = (TextView) findViewById(R.id.pop);
		mListView = (ListView) findViewById(R.id.mlistview);
		data = new ArrayList<String>();
		data.add(getResources().getString(R.string.search_choice_goods));
		data.add(getResources().getString(R.string.search_choice_shop));

		mPopSpinner = new PopupSpinnerView(this);
		// mPopSpinner.setData(data);
		mPopSpinner.setData(data, 0xFF333333, 0xFFFFFFFF, 18, 0xFFFFFFFF,
				0xFF333333);
		mPopSpinner.setDivider(2, new ColorDrawable(0xFF444444));
		mPopSpinner.setOnPopupListener(new OnPopupItemListener() {

			public void OnItemClick(boolean popupFlag, int pos) {
				// TODO Auto-generated method stub
				mPopText.setText(data.get(pos));
			}

		});
		mPopText.setOnClickListener(new OnClickListener() {

			public void onClick(View v) {
				// TODO Auto-generated method stub
				mPopSpinner.show(mPopText);
			}

		});

		sharedata = new ArrayList<BaseDataInterface>();

		PopupSpinnerData psData;

		psData = new PopupSpinnerData();
		psData.setString("taobao");
		BitmapDrawable drawable = (BitmapDrawable) getResources().getDrawable(
				R.drawable.icon);
		psData.setDrawable(drawable);
		sharedata.add(psData);

		psData = new PopupSpinnerData();
		psData.setString("juhuasuan");
		drawable = (BitmapDrawable) getResources().getDrawable(
				R.drawable.icon_ju);
		psData.setDrawable(drawable);
		sharedata.add(psData);

		psData = new PopupSpinnerData();
		psData.setString("caipiao");
		drawable = (BitmapDrawable) getResources().getDrawable(
				R.drawable.icon_lottery);
		psData.setDrawable(drawable);
		sharedata.add(psData);

		mPopSpinner2 = new PopupSpinnerView(this);
		mPopSpinner2.setImageData(sharedata, 0xFF333333, 0xFFFFFFFF, 18,
				0xFFFFFFFF, 0xFF333333);

		mPopSpinner2.setDivider(1, new ColorDrawable(Color.WHITE));
		mPopSpinner2.setWidth(300);
		mPopTextImage = (TextView) findViewById(R.id.pop2);
		mPopTextImage.setOnClickListener(new OnClickListener() {

			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				mPopSpinner2.show(mPopTextImage);
			}

		});

		mPopSpinner2.setOnPopupListener(new OnPopupItemListener() {

			public void OnItemClick(boolean popupFlag, int pos) {
				// TODO Auto-generated method stub

				BaseDataInterface data = sharedata.get(pos);
				mPopTextImage.setText(data.getString());
				mPopSpinner.dismiss();
			}

		});
	}
}